package com.yesido.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author yesido
 * @description
 * @date 2023-06-05 23:34
 * @Version 8.3
 */
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients(basePackages = {"com.yesido.springcloud.feign.service"})
public class FeignConsumer {
    public static void main(String[] args) {
        SpringApplication.run(FeignConsumer.class,args);
    }

    /**
     * 实现简单的负载均衡 通过微服务的名字来访问
     * http://localhost:8081/ribbon/getUserById/1 轮询db01 和db02
     * 也就是轮询provider_8101 provider_8102两个服务
     * @return
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return  new RestTemplate();
    }
}
